﻿using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

	[XmlRoot("scores")]
	public class ScoreContainer 
	{
		[XmlElement("player")]
		public Player[] Players;

		public void Save(string path)
		{
		var serializer = new XmlSerializer(typeof(ScoreContainer));
			using (var stream = new FileStream(path, FileMode.Create))
			{
				serializer.Serialize(stream, this);
			}
		}
		
	public static ScoreContainer Load(string path)
		{
		var serializer = new XmlSerializer(typeof(ScoreContainer));
			using (var stream = new FileStream(path, FileMode.Open))
			{
			return serializer.Deserialize(stream) as ScoreContainer;
			}
		}
		
		//Loads the xml directly from the given string. Useful in combination with www.text.
	public static ScoreContainer LoadFromText(string text)
		{
		var serializer = new XmlSerializer(typeof(ScoreContainer));
		return serializer.Deserialize(new StringReader(text)) as ScoreContainer;
		}
	}

